<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>新闻管理</title>
    <link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/js/jquery-1.11.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>

    <script>
        var chekedi = 1;
        <%--$(function () {--%>

        <%--    $("[name='juan']").val(${juan});--%>
        <%--    $("[name='date']").val("${condition.date}")--%>
        <%--    $('[name="user_id"]').val(${users_id})--%>
        <%--    $("[name='name']").val("${condition.name}")--%>
        <%--    $("[name='id']").val("${condition.id}")--%>
        <%--})--%>
        <%--var juan =${juan};--%>
        <%--var juansum =${juansum};--%>


        function qx() {
            if (chekedi == 1) {

                $('[name="new"]').prop("checked", true);
                chekedi = 0;
            } else if (chekedi == 0) {
                $('[name="new"]').prop("checked", false);
                chekedi = 1;
            }

        }

        function delall() {
            var str = "";
            for (var i = 0; i < $('[type="checkbox"]').length; i++) {
                if ($('[type="checkbox"]').get(i).checked) {
                    if ($('[type="checkbox"]').get(i).id != "全选") {
                        str += $('[type="checkbox"]').get(i).value.toString() + ","
                    }

                }

            }
            if (str != "") {
                location.href = "${pageContext.request.contextPath}/admin/deleteNews?id=" + str;
            } else {
                alert("请选中你要删除的数据，可多选");
            }


        }
    </script>
</head>
<body>
<div style="height: 80px;width: 100%;overflow: hidden">

    <jsp:include page="inc/top.jsp"></jsp:include>
</div>
<div style="float: left;width: 187px;height: calc(100% - 80px);overflow: hidden">
    <jsp:include page="inc/left.jsp"></jsp:include>
</div>
<div style="float: left;width: calc(100% - 187px);height: calc(100% - 80px);overflow: scroll">
    <ol class="breadcrumb">
        位置：
        <li><a href="#">新闻管理</a></li>
        <li class="active">新闻管理</li>


    </ol>
    <div class="container-fluid">

        <div class="row">
            <center>
                <form id="frm" class="form-inline" action="${pageContext.request.contextPath}/admin/showNews" method="get">
                    <div class="form-group">
                        <label for="exampleInputName2">新闻ID：</label>
                        <input type="text" class="form-control" id="exampleInputName2" name="id"
                               placeholder="请填写整数的新闻ID">
                    </div>
                    <div class="form-group">
                        <label for="exampleInputEmail2">新闻标题：</label>
                        <input type="text" class="form-control" id="exampleInputEmail2" name="name"
                               placeholder="可模糊查询">
                    </div>
                    <div class="form-group">
                        <label>发布人：</label>
                        <select name="userId" class="form-control">
                            <option></option>
                            <c:forEach var="x" items="${users}">
                                <option value="${x.id}">${x.username}</option>
                            </c:forEach>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>发布日期：</label>
                        <input type="date" class="form-control" name="date" placeholder="请选择发布日期">
                    </div>
                    <input type="hidden" name="juan" value="1" class="form-control">
                    <input type="hidden" name="page" value="1" class="form-control">
                    <button type="submit" class="btn btn-default">查询</button>
                </form>
            </center>
        </div>
        <div class="row" style="margin-bottom: 10px">
            <div class="col-md-1 col-md-offset-9">
                <a href="${pageContext.request.contextPath}/admin/addNews">
                    <button type="button" class="btn btn-success">添加新闻</button>
                </a>
            </div>
            <div class="col-md-1" style="margin-left: 20px">
                <button type="button" class="btn btn-danger" onclick="delall()">删除新闻</button>
            </div>
        </div>
        <div style="height: 60%">
            <table class="table table-bordered table-hover" style="text-align: center">

                <tr>
                    <th style="text-align: center"><input type="checkbox" id="全选" onclick="qx()"></th>
                    <th style="text-align: center">新闻ID</th>
                    <th style="text-align: center">新闻标题</th>
                    <th style="text-align: center">新闻发布时间</th>
                    <th style="text-align: center">新闻发布人</th>
                    <th style="text-align: center"><span class="glyphicon glyphicon-pencil"></span>&nbsp;编辑</th>
                    <th style="text-align: center"><span class="glyphicon glyphicon-trash"></span>&nbsp;删除</th>
                </tr>
                <c:forEach var="x" items="${dateList.list}">
                    <tr>
                        <td><input type="checkbox" name="news" value="${x.id}"></td>
                        <td><c:out value="${x.id}" escapeXml="false"></c:out></td>
                        <td><c:out value="${x.name}" escapeXml="false"></c:out></td>
                        <td><c:out value="${x.date}" escapeXml="false"></c:out></td>
                        <td><c:out value="${x.user.username}" escapeXml="false"></c:out></td>
                        <td><a href="${pageContext.request.contextPath}/admin/editNews?id=${x.id}" style="+text-decoration: none"><span
                                class="glyphicon glyphicon-pencil"></span>&nbsp;编辑</a>
                        </td>
                        <td><a href="${pageContext.request.contextPath}/admin/deleteNews?id=${x.id}" style="text-decoration: none"><span
                                class="glyphicon glyphicon-trash"></span>&nbsp;删除</a>
                        </td>
                    </tr>
                </c:forEach>

            </table>
        </div>

        <div class="row">
            <div class="col-col-4 col-md-4 col-sm-4 col-xs-4">
                <p>当前第${dateList.page}页/共${dateList.pageCount}页 总记录数共${dateList.count}条</p>
            </div>
            <nav aria-label="Page navigation">
                <ul class="pagination">

                    <li>
                        <a href="${pageContext.request.contextPath}/admin/showNews?page=${dateList.page-1<1?1:(dateList.page-1)}&name=${name}&id=${id}&userId=${userId}&date=${date}" aria-label="Previous">
                            <span aria-hidden="true">上一页</span>
                        </a>
                    </li>
                    <c:forEach begin="1" end="${dateList.pageCount}" step="1" var="index">
                        <li><a href="${pageContext.request.contextPath}/admin/showNews?page=${index}&name=${name}&id=${id}&userId=${userId}&date=${date}">${index}</a></li>
                    </c:forEach>
                    <li>
                        <a href="${pageContext.request.contextPath}/admin/showNews?page=${(dateList.page+1>dataList.pageCount)?dataList.pageCount:(dataList.page+1)}&name=${name}&id=${id}&userId=${userId}&date=${date}" aria-label="Next">
                            <span aria-hidden="true">下一页</span>
                        </a>
                    </li>
                </ul>
            </nav>
        </div>
    </div>
</div>
</body>
</html>
